/*******************************************************
*  Team name: FTPMP
*  Class involve: EventCardWindow, EventCardController
*  Version, Author, History of modification: 
*  Version 1.0, Fred,
*  	-EventCardWindow Constuctor
*  Version 1.1, Fred, 
* 	- Add JLabel, JButton
********************************************************/

package boundary;

import java.awt.CardLayout;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JLabel;

import control.EventCardController;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class EventCardWindow extends CardWindow implements ActionListener {
	EventCardController eventCardController;
	JLabel eventName;
	JLabel [] hints;
	JButton [] opt;
	String[] options;
	int choice;
	int k;
	int playerID;
	int eventID;
	
	public EventCardWindow(CardLayout cl, RoundWindow RW, EventCardController eventCardController) {
		super(cl,RW);
		JLabel title = new JLabel("Event Card");
		super.CardPanel.add(title);
		this.eventCardController=eventCardController;
		this.eventCardController.initEventCardWindow(this);
	}

	public void process() {
		this.eventCardController.answeredEvent(this.choice, this.playerID, this.eventID);
	}
	
	public void setDisplay() {
	
	}
	
	public void setLabel(String[] opts, String[] hint, String name, int pid, int eid)
	{
		roundWindow.printEventPanel();
		int n=0;
		this.playerID = pid;
		this.eventID = eid;
		this.eventName = new JLabel(name);
		this.options = opts;
		this.opt=new JButton[opts.length];
		this.hints=new JLabel[hint.length];
		
		for(int i=0; i<opts.length; i++) {
			opt[i] = new JButton(opts[i]);
		}
		
		for(int i=0; i<hint.length; i++) {
			hints[i] = new JLabel(hint[i]);
		}
		
		setLayout(null);
		this.eventName.setFont(new Font("Dialog", Font.PLAIN, 16));
		this.eventName.setBounds(156, 108, 489, 192);
		add(eventName);
		
		
		for(int i=0; i<opt.length; i++) {
			opt[i].setFont(new Font("Dialog", Font.PLAIN, 14));
			
			if(i<=1)
				opt[i].setBounds(135+(i*285), 310, 242, 95);
			else
				opt[i].setBounds(135+((i+1)%3*285), 416, 242, 95);
			add(opt[i]);
			opt[i].addActionListener(this);
		}
		
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==opt[0])
			choice = 0;
		else if(e.getSource()==opt[1])
			choice = 1;
		else if(e.getSource()==opt[2])
			choice = 2;
		else
			choice = 3;
		
		process();
		roundWindow.printBoardPanel();
        roundWindow.printMTPanel();
	}
	
	public String getJLabel()
	{
		return this.eventName.getText();
	}
}